package flyweight.fromKanYun;

import java.util.HashMap;
import java.util.Map;

/**
 * 亨元工厂：负责创建和管理亨元对象
 */
public class FlyweightFactory {
    private Map<String,FlyWeight> map = new HashMap<String,FlyWeight>();

    /*获取亨元对象*/
    public FlyWeight getFlyWeight(String key){
        FlyWeight flyWeight = map.get(key);
        if (flyWeight == null){
            flyWeight = new SubFlyWeight(key);
            map.put(key,flyWeight);
        }
        return flyWeight;
    }

    public int getCount(){
        return map.size();
    }

}
